package top.fullj.remoting.provider;

import java.lang.reflect.Method;

/**
 * @author bruce.wu
 * @since 2022/2/14 14:10
 */
class ServiceDelegate {

    private final Object target;

    private final ServiceConfig config;

    ServiceDelegate(Object target, ServiceConfig config) {
        this.target = target;
        this.config = config;
    }

    Object invoke(String methodName, Object[] args, Class<?>[] types) throws Exception {
        /*if (args != null) {
            Class<?>[] types = new Class<?>[args.length];
            for (int i = 0; i < args.length; i++) {
                types[i] = args[i].getClass();
            }
            Method method = target.getClass().getMethod(methodName, types);
            return method.invoke(target, args);
        } else {
            Method method = target.getClass().getMethod(methodName);
            return method.invoke(target);
        }*/
        Method method = target.getClass().getMethod(methodName, types);
        return method.invoke(target, args);
    }

}
